
find_package(CUDA REQUIRED)

find_path(TENSORRT_INCLUDE_DIR NvInfer.h
        HINTS ${TENSORRT_ROOT} ${CUDA_TOOLKIT_ROOT_DIR}
        PATH_SUFFIXES include/)
message(STATUS "Found TensorRT headers at ${TENSORRT_INCLUDE_DIR}")
find_library(TENSORRT_LIBRARY_INFER nvinfer
        HINTS ${TENSORRT_ROOT} ${TENSORRT_BUILD} ${CUDA_TOOLKIT_ROOT_DIR}
        PATH_SUFFIXES lib lib64 lib/x64)
message(STATUS "Found TensorRT libs ${TENSORRT_LIBRARY_INFER}")

find_package(OpenCV REQUIRED)
link_directories(${OpenCV_LIBRARIES_DIRS})

find_package(Boost REQUIRED COMPONENTS
filesystem 
system
thread
)
if(NOT Boost_FOUND)
    message(ERROR "Not found Boost")
endif()

find_package(Protobuf REQUIRED)

if(NOT Protobuf_FOUND)
    message(ERROR "Not found Protobuf")
endif()

#---------------------generated code-------------------------------#
file(GLOB PROTO_FILES ${PROJECT_SOURCE_DIR}/proto/*.proto)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${PROTO_FILES})
SET_PROPERTY(SOURCE ${PROTO_SRCS} PROPERTY COMPILE_FLAGS "-Wno-error=unused-parameter")


file(GLOB CPP_SRC *.cpp)
file(GLOB CU_SRC cuda/*.cu)

file(GLOB TER_CPP_SRC ./tensorrt/*.cpp)
file(GLOB TRT_CU_SRC ./tensorrt/*.cu)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -Wall -Ofast")
list(APPEND CUDA_NVCC_FLAGS "-D_FORCE_INLINES -Xcompiler -fPIC ")
set(CUDA_ARCH "-gencode;arch=compute_75,code=sm_75" )

include_directories(${CUDA_INCLUDE_DIRS}
                    ${TENSORRT_INCLUDE_DIR}
                    ${OpenCV_INCLUDE_DIRS}
                    ${PROJECT_SOURCE_DIR}/include
                    ${PROTOBUF_INCLUDE_DIRS}
                    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/detection_vision>
                    $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src/detection_vision>
                    $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)
                    #../onnx-tensorrt)
cuda_add_library(ctdet SHARED 
                 ${CPP_SRC}
                 ${CU_SRC}
                 ${TER_CPP_SRC}
                 ${TRT_CU_SRC}
                 ${PROTO_SRCS}
                 ${PROTO_HDRS}
                 ${SOURCE}
                 )
target_link_libraries(ctdet
        ${TENSORRT_LIBRARY_INFER}
        ${OpenCV_LIBS}
        ${Boost_LIBRARIES}
        nvonnxparser
        nvonnxparser_runtime
        glog::glog)
set(CMAKE_STAGING_PREFIX /opt/adc)
install(TARGETS ctdet
        ARCHIVE DESTINATION ${CMAKE_STAGING_PREFIX}/lib
        LIBRARY DESTINATION ${CMAKE_STAGING_PREFIX}/lib
       # RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
      )
